<!DOCTYPE html>
<html>
<head>
    <title>地区管理</title>
    <#include "/header.html">
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <div style="margin: 10px 0">
            <form class="layui-form layui-form-pane" action="" id="searchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="name" placeholder="搜索名称" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">等级</label>
                        <div class="layui-input-inline">
                            <select name="grade">
                                <option value=""></option>
                                <option value="1">省</option>
                                <option value="2">市</option>
                                <option value="3">区</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button type="submit" class="layui-btn layui-btn-primary layui-border-blue" lay-submit lay-filter="form-search-btn"><i class="layui-icon layui-icon-search"></i>搜索</button>
                        <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="form-reset-btn"><i class="layui-icon layui-icon-refresh"></i>重置</button>
                    </div>
                </div>
            </form>
        </div>

        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
    </div>
</div>

<script type="text/html" id="currentTableGradeTpl">
    {{# if(d.grade == 1){ }}
    <span class="layui-badge layui-bg-gray">省</span>
    {{# } else if(d.grade == 2){ }}
    <span class="layui-badge layui-bg-gray">市</span>
    {{# } else if(d.grade == 3){ }}
    <span class="layui-badge layui-bg-gray">区</span>
    {{# } else { }}
    <span></span>
    {{# } }}
</script>

<script type="text/html" id="currentTableTypeTpl">
    {{# if(d.type == 1){ }}
    <span class="layui-badge-rim">偏远地区</span>
    {{# } else if(d.type == 2){ }}
    <span class="layui-badge-rim">港澳台</span>
    {{# } else { }}
    <span class="layui-badge-rim">经济区</span>
    {{# } }}
</script>

<script type="text/html" id="currentTableBar">
    <#if shiro.hasPermission("sys:config:update")>
    <a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
    </#if>
</script>

<script>
    var formDataId = 0;
    layui.use(['form','table'], function () {
        var $ = layui.jquery,
        	form = layui.form,
            table = layui.table;
		tableSearch({},'region/list');
        
        function tableSearch(data,url) {
        	var tablethis = table.render({
                elem: '#currentTableId',
			    where:data,
                url: serverUrl(url),
                // toolbar: '#toolbarDemo',
                defaultToolbar: [],
                cols: [[
                    {type: "numbers", width: 80},
                    {field: 'id', minWidth: 100, title: '行政代码'},
                    {field: 'name', minWidth: 100, title: '名称'},
                    {field: 'grade', minWidth: 100, title: '行政等级', templet: '#currentTableGradeTpl'},
                    {field: 'type', minWidth: 100, title: '地区类型', templet: '#currentTableTypeTpl'},
                    {field: 'latitude', minWidth: 100, title: '纬度'},
                    {field: 'longitude', minWidth: 100, title: '经度'},
                    {title: '操作', width: 120, toolbar: '#currentTableBar', align: "center"}
                ]],
                limits: [15, 30, 50],
                limit: 15,
                page: true
            });
        	return tablethis;
        };
        table.on('tool(currentTableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'edit') {
                formDataId = data.id;
                openFormView('app/region/form.html', '编辑地区');
                return false;
            }
        });
     // 监听搜索操作
        form.on('submit(form-search-btn)', function (data) {
            //执行搜索重载
            if (data.field.name||data.field.grade) {
            	tableSearch({"name":data.field.name,"grade":data.field.grade},'region/search');
            //table.filterData(data.field.name);
	        } else {
	            table.clearFilter();
	        }
	        return false;
	    });
        form.on('submit(form-reset-btn)', function (data) {
        	tableSearch({},'region/list');
            $("#searchForm")[0].reset();
            table.clearFilter();
            return false;
        });
    });
</script>

</body>
</html>